<template>
	<view>
		<view class="search-box">
			<!-- 搜索组件 -->
			<u-search placeholder="请输入搜索内容" :show-action="false" height="70" @change="input"></u-search>
		</view>
		<!-- 搜索建议列表 -->
		<view class="sugg-list" v-if="searchResults.length !== 0">
			<block  v-for="(item, i) in searchResults" :key="i" >
				<sousuo-list-item :item="item"></sousuo-list-item>
			</block>
		</view>
		<!-- 搜索历史 -->
		<view class="history-box" v-else>
			<!-- 标题区域 -->
			<view class="history-title">
				<text>搜索历史</text>
				<uni-icons type="trash" size="17" @click="clean"></uni-icons>
			</view>
			<!-- 列表区域 -->
			<view class="history-list">
				<uni-tag :text="item" v-for="(item, i) in histories" :key="i" @click="gotoGoodsList(item)"></uni-tag>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		searchList
	} from '@/utils/good_list.js'
	export default {
		data() {
			return {
				showSync: true,
				// 搜索的结果列表
				searchResults: [],
				// 搜索历史的数组
				historyList: ['a', 'app']
			}
		},
		onLoad() {
			// this.historyList = JSON.parse(uni.getStorageSync('kw') || '[]')
		},
		methods: {
			// input 输入事件的处理函数
			input(e) {
				console.log(e);
				this.searchResults = searchList;
				if (!e) {
					this.searchResults = []
				}
			},
			
		},

		computed: {
			histories() {
				return [this.historyList].reverse()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.search-box {
		position: sticky;
		background-color: #C00000;
		padding: 15rpx 32rpx;
		top: 0;
		z-index: 2;
	}

	.sugg-list {
		padding: 0 5px;

		
	}

	.history-box {
		padding: 0 5px;

		.history-title {
			display: flex;
			justify-content: space-between;
			height: 40px;
			align-items: center;
			font-size: 13px;
			border-bottom: 1px solid #efefef;
		}

		.history-list {
			display: flex;
			flex-wrap: wrap;

			.uni-tag {
				margin-top: 5px;
				margin-right: 5px;
			}
		}
	}
</style>
